package com.snow.useviewdemo.util.lifecyler;

import android.app.Application;

import java.util.List;

/**
 * Created by zhaoyingtao
 * Date: 2020/12/15
 * Describe:前后台生命周期
 * ActivityLifecycleCallbacks接口介绍
 * 官方地址：https://developer.android.com/reference/android/app/Application.ActivityLifecycleCallbacks
 */
public class SNLifecycleHelper {

    public static void setWhiteList(List<Class> whiteList) {
        SNForegroundCallbacks.setWhiteClass(whiteList);
    }

    /**
     * 注册APP生命周期监测
     *
     * @param application
     * @param listener
     */
    public static void registerActivityLifecycle(Application application, SNLifecycleListener listener) {
        SNForegroundCallbacks.init(application);
        SNForegroundCallbacks.get().addListener(listener);

    }

    /**
     * 判断是否是前台
     *
     * @return
     */
    public static boolean isForeground() {
        return SNForegroundCallbacks.get().isForeground();
    }

    /**
     * 判断是否是后台
     *
     * @return
     */
    public static boolean isBackground() {
        return SNForegroundCallbacks.get().isBackground();
    }
}
